module GSWH 

where 

nofactor :: Integer -> Integer -> Bool
nofactor m n = rem n m /= 0

prime :: Integer -> Bool
prime n | n < 1     = error "not a positive integer"
        | n == 1    = False 
        | otherwise = nofactors 2 n 

nofactors :: Integer -> Integer -> Bool
nofactors m n | m^2 > n   = True 
              | otherwise = nofactor m n && nofactors (m+1) n

mnmInt :: [Int] -> Int
mnmInt [] = error "empty list" 
mnmInt [x] = x
mnmInt (x:xs) = min x (mnmInt xs)

min' :: Int -> Int -> Int 
min' x y | x <= y    = x
         | otherwise = y 

{-- the following needs code for 'remove' 

srtInts :: [Int] -> [Int] 
srtInts [] = []
srtInts xs = m : (srtInts (remove m xs)) where m = mnmInt xs 

                                                            --} 

average :: [Int] -> Float
average [] = error "empty list" 
average xs = fromInt (sum xs) / fromInt (length xs)

sum' :: [Int] -> Int
sum' [] = 0 
sum' (x:xs) = x + sum' xs

length' :: [a] -> Int
length' [] = 0 
length' (x:xs) = 1 + length' xs

prefix :: String -> String -> Bool
prefix [] ys = True
prefix (x:xs) [] = False
prefix (x:xs) (y:ys) = (x==y) && prefix xs ys 

a = 3
b = 4 
f :: Integer -> Integer -> Integer
f x y = x^2 + y^2
